---
title: "R6.Ideology_Trends"
---

# Load Packages
```{r}
library(tidyverse)
```

# Load data
```{r}
load("Data/voters_list.Rdata")
```

# Plot Vote Share Trends/Ideological Grouping in ZIRA over Time
```{r}
zira_panel <- do.call(rbind, voters_list[1:7]) %>%
  rename(Party = ideology2, Votes = votes) %>% 
  mutate(election = as.character(election)) %>% 
  mutate(Party = ifelse(Party == "Center", "Center-Left", Party), 
         Party = ifelse(Party == "Left", "Far Left", Party))

years <- data.frame(election = c("AC75", "AR76", "AR79", "AR80", "AR83", "AR85", "AR87"), 
           year = as.factor(c(1975, 1976, 1979, 1980, 1983, 1985, 1987)))
zira_panel <- zira_panel %>% left_join(years)

zira_panel$Party <- factor(zira_panel$Party, level = c("Communist", "Far Left", "Center-Left", "Right"))
   
ggplot(zira_panel %>% group_by(year, Party) %>% summarise(across(Votes, sum)) %>% mutate(vs = Votes/sum(Votes)),
             aes(x = year, col = as.factor(Party), shape = Party, group = Party)) +
        geom_point(aes(y = vs)) +
        geom_line(aes(y = vs)) +
        theme_light() + 
        xlab("Election Year") + ylab("Vote Share") +
        scale_color_grey(name = "Ideology") +
        scale_shape_discrete(name = "Ideology") +
        theme(axis.text.x = element_text(angle = 90)) 

ggsave(plot = last_plot(),
       "Figures/Afg1d2_VSZIRA.pdf",
       width = 7, height = 5)
 
```
